package teach.day05;

import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;

//堆   优先级队列

public class P05PriorityQueueDemo {
    public static void main(String[] args) {
        int[] a = {1,3,5,7,9,2,4,6,8,0};

        Queue<Integer> Q = new PriorityQueue<>(Collections.reverseOrder()); //大顶堆定义 jdk>=1.8
        Queue<Integer> Q2 = new PriorityQueue<>(a.length, Collections.reverseOrder()); //大顶堆定义 jdk<1.8
//        Queue<Integer> Q = new PriorityQueue<>();     //小顶堆定义
//        Queue<Integer> Q = new LinkedList<>();
        for (Integer e : a) {
            Q.offer(e);
        }
        while (!Q.isEmpty()) {
            System.out.println(Q.peek());
            Q.poll();
        }
    }
}
